package com.wangxu.blog.handler;

import com.wangxu.blog.vo.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

//对加了@Controller注解的类进行拦截处理  AOP的实现
@ControllerAdvice
public class AllExceptionHandler {

    /**
     * //@ControllerAdvice 配合 @ExceptionHandler 实现全局异常处理
     */
    @ExceptionHandler(Exception.class)
    @ResponseBody //返回json数据
    public Result doException(Exception e){
        e.printStackTrace();
        return Result.fail(-999,"系统异常");
    }
}
